<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <script src="/js/jquery-2.1.4.min.js"></script>
</head>
<body>
<div>
    <script>
        function login() {
            $.ajax({
                url: "/authentication/form",
                method: "post",
                data: {
                    username: $('#username').val(),
                    password: $('#pwd').val(),
                    imageCode: $('#code').val()
                },
                success: function (result) {
                    console.log(result)
                    if(result.authorities[0].authority == 'ROLE_teacher'){
                        window.location.href = "/teacher/index.html";
                    }else{
                        window.location.href = "/student/index.html";
                    }
                    // window.location.href = "/teacher/index.html";
                },
                error: function (res) {
                    console.log(res)
                }
            })
        }
    </script>
    <h2>标准登录页面</h2>
    <!--自定义处理URL，通过配置让UsernamePasswordxxFilter处理-->
    <form method="post" action="/authentication/form">
        <div>
            <label>用户名：</label>
            <input type="text" id="username" name="username" value="teacher1">
        </div>
        <div>
            <label>密码：</label>
            <input type="password" id="pwd" name="password" value="123">
        </div>
        <div>
            <label>验证码</label>
            <input name="imageCode" id="code" type="text" value=""/>
            <img src="/code/image?width=75&s=a" id="codeImg"/>
        </div>
        <!--<div>-->
        <!--<label>记住我</label>-->
        <!--<input name="remember-me" id="rememberMe" type="checkbox" value="true" />-->
        <!--</div>-->
        <div>
            <button type="button" onclick="login()" onkeydown="if(this.keyCode==13)login()">登录</button>
        </div>
    </form>
</div>

<script>
    $('#codeImg').click(function () {
        this.src = this.src+"a"
    })
</script>
</body>
</html>